home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / tclX6.4c / dist / tests / dup.test < prev    next >
Encoding:
Text File  |  1992-11-07  |  2.0 KB  |  85 lines

  1. #
  2. # dup.test
  3. #
  4. # Tests for the dup command.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: dup.test,v 2.0 1992/10/16 04:49:38 markd Rel $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21.  
  22. # Create a test file
  23.  
  24. catch {unlink {DUP.TMP}}
  25.  
  26. set testFH [open DUP.TMP w]
  27. for {set cnt 0} {$cnt < 100} {incr cnt} {
  28.      puts $testFH [GenRec $cnt]
  29. }
  30. close $testFH
  31.  
  32. test iocmds-2.1 {dup tests} {
  33.     set testFH [open DUP.TMP]
  34.     set testFH2 [dup $testFH]
  35.     gets $testFH2 testRec
  36.     close $testFH
  37.     close $testFH2
  38.     set testRec
  39. } [GenRec 0]
  40.  
  41. set data {{now is the time}    {for all good programmers} 
  42.           {to come to the aid} {of their software}}
  43. set inFH [open INCMDS.TMP w]
  44. catch {unlink OUTPUT.TMP}
  45. foreach line $data {
  46.     puts $inFH "puts stdout \"$line\""
  47. }
  48. puts $inFH {flush stdout}
  49. puts $inFH {exit 0}
  50. close $inFH
  51.  
  52. flush stdout
  53. flush stderr
  54.  
  55. if {[set childPid [fork]] == 0} {
  56.     set inFH  [open INCMDS.TMP r]
  57.     set outFH [open OUTPUT.TMP w]
  58.  
  59.     close stdin
  60.     dup $inFH stdin
  61.     close $inFH
  62.  
  63.     close stdout
  64.     dup $outFH stdout
  65.     close $outFH
  66.         
  67.     execl ../tcl [list -qc {commandloop {return ""} {return ""}}]
  68.     error "Should never make it here"
  69. }
  70.  
  71. test iocmds-2.2 {dup tests} {
  72.     wait $childPid
  73. } "$childPid EXIT 0"
  74.  
  75. set outFH [open OUTPUT.TMP r]
  76. foreach line $data {
  77.     test iocmds-2.3 {dup tests} {
  78.         gets $outFH
  79.     } $line
  80. }
  81. close $outFH
  82.  
  83. catch {unlink {DUP.TMP}}
  84.  
  85.